<html>
<head><meta charset="utf-8"><title>What&#x27;s the best way to report fatal errors? · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/What&#x27;s.20the.20best.20way.20to.20report.20fatal.20errors.3F.html">What&#x27;s the best way to report fatal errors?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="173231536"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/What%27s%20the%20best%20way%20to%20report%20fatal%20errors%3F/near/173231536" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/What&#x27;s.20the.20best.20way.20to.20report.20fatal.20errors.3F.html#173231536">(Aug 14 2019 at 18:57)</a>:</h4>
<p>At the moment, lexer <a href="https://github.com/rust-lang/rust/blob/c43d03a19f326f4a323569328cc501e86eb6d22e/src/libsyntax/parse/lexer/mod.rs#L375" target="_blank" title="https://github.com/rust-lang/rust/blob/c43d03a19f326f4a323569328cc501e86eb6d22e/src/libsyntax/parse/lexer/mod.rs#L375">panics</a> on some errors.</p>
<p>I think panicking is bad for compiler (it certainly is bad for IDEs), and I'd like to fix it. What's the correct way of doing it?</p>
<p>I would think that I should still report a diagnostic with <code>Fatal</code> severity, but just avoid actually raising <code>FatalError</code>. However, <code>#[must_use]</code> on <code>FatalError</code> seems to hint that, if you produced a <code>Fatal</code> diagnostics, you <em>must</em> panic.</p>
<p>Should I just produce an <code>Error</code>? Should I use <code>PhaseFatal</code>?</p>
<p>If <code>FatalError</code> always panics and we want to move away from panicing, should we add a comment saying "don't add new usages of <code>FatalError</code> and try to remove existing ones"?</p>



<a name="173231586"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/What%27s%20the%20best%20way%20to%20report%20fatal%20errors%3F/near/173231586" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/What&#x27;s.20the.20best.20way.20to.20report.20fatal.20errors.3F.html#173231586">(Aug 14 2019 at 18:57)</a>:</h4>
<p>IIRC, there's a way to call something like exit_if_errors?</p>



<a name="173231640"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/What%27s%20the%20best%20way%20to%20report%20fatal%20errors%3F/near/173231640" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/What&#x27;s.20the.20best.20way.20to.20report.20fatal.20errors.3F.html#173231640">(Aug 14 2019 at 18:58)</a>:</h4>
<p>That's probably what you want after emitting just a regular error</p>



<a name="173231656"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/What%27s%20the%20best%20way%20to%20report%20fatal%20errors%3F/near/173231656" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/What&#x27;s.20the.20best.20way.20to.20report.20fatal.20errors.3F.html#173231656">(Aug 14 2019 at 18:58)</a>:</h4>
<p><code>abort_if_errors</code>, yeah</p>



<a name="173231703"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/What%27s%20the%20best%20way%20to%20report%20fatal%20errors%3F/near/173231703" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/What&#x27;s.20the.20best.20way.20to.20report.20fatal.20errors.3F.html#173231703">(Aug 14 2019 at 18:59)</a>:</h4>
<p>Yeah, I think that should work, right? Or is there something I'm missing? Presumably FatalError.raise() could just call abort_if_errors (modulo global session and such, but we can thread it through I think)</p>



<a name="173231741"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/What%27s%20the%20best%20way%20to%20report%20fatal%20errors%3F/near/173231741" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/What&#x27;s.20the.20best.20way.20to.20report.20fatal.20errors.3F.html#173231741">(Aug 14 2019 at 18:59)</a>:</h4>
<p>That doesn't discriminate between recoverable errors and "oh noes, don't even try to run further phases of the compiler to avoid the flood of cascading errors"</p>



<a name="173231799"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/What%27s%20the%20best%20way%20to%20report%20fatal%20errors%3F/near/173231799" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/What&#x27;s.20the.20best.20way.20to.20report.20fatal.20errors.3F.html#173231799">(Aug 14 2019 at 19:00)</a>:</h4>
<blockquote>
<p>FatalError.raise() could just call abort_if_errors (modulo global session and such, but we can thread it through I think)</p>
</blockquote>
<p>It's the other way arround: abort_if_errors calls <code>FatalError.raise()</code> :D</p>



<a name="173231834"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/What%27s%20the%20best%20way%20to%20report%20fatal%20errors%3F/near/173231834" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/What&#x27;s.20the.20best.20way.20to.20report.20fatal.20errors.3F.html#173231834">(Aug 14 2019 at 19:01)</a>:</h4>
<p>I assume in this case there's no choice but to fatally abort?</p>



<a name="173231842"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/What%27s%20the%20best%20way%20to%20report%20fatal%20errors%3F/near/173231842" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/What&#x27;s.20the.20best.20way.20to.20report.20fatal.20errors.3F.html#173231842">(Aug 14 2019 at 19:01)</a>:</h4>
<p>hm, but you implied FatalError.raise() panics?</p>



<a name="173231852"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/What%27s%20the%20best%20way%20to%20report%20fatal%20errors%3F/near/173231852" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/What&#x27;s.20the.20best.20way.20to.20report.20fatal.20errors.3F.html#173231852">(Aug 14 2019 at 19:01)</a>:</h4>
<p>which I didn't think was the case</p>



<a name="173231949"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/What%27s%20the%20best%20way%20to%20report%20fatal%20errors%3F/near/173231949" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/What&#x27;s.20the.20best.20way.20to.20report.20fatal.20errors.3F.html#173231949">(Aug 14 2019 at 19:02)</a>:</h4>
<p>Sorry for the sloppy wording: <code>FatalError.raise</code> unwinds (via resume unwind, not via panic), and I assume that we don't actually want that behavior for "something's wrong with user's code"</p>



<a name="173232121"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/What%27s%20the%20best%20way%20to%20report%20fatal%20errors%3F/near/173232121" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/What&#x27;s.20the.20best.20way.20to.20report.20fatal.20errors.3F.html#173232121">(Aug 14 2019 at 19:04)</a>:</h4>
<p><span class="user-mention" data-user-id="126931">@centril</span> on the contrary, in the lexer's case, we can just print an error, produce a fake token and chug along. However that <em>might</em> trigger cascading errors.</p>



<a name="173232153"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/What%27s%20the%20best%20way%20to%20report%20fatal%20errors%3F/near/173232153" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/What&#x27;s.20the.20best.20way.20to.20report.20fatal.20errors.3F.html#173232153">(Aug 14 2019 at 19:04)</a>:</h4>
<p>do we need an <code>::Err</code> token to avoid cascading errors?</p>



<a name="173232194"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/What%27s%20the%20best%20way%20to%20report%20fatal%20errors%3F/near/173232194" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/What&#x27;s.20the.20best.20way.20to.20report.20fatal.20errors.3F.html#173232194">(Aug 14 2019 at 19:04)</a>:</h4>
<p>cc <span class="user-mention" data-user-id="123856">@Vadim Petrochenkov</span> <span class="user-mention" data-user-id="119031">@Esteban Küber</span></p>



<a name="173233086"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/What%27s%20the%20best%20way%20to%20report%20fatal%20errors%3F/near/173233086" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/What&#x27;s.20the.20best.20way.20to.20report.20fatal.20errors.3F.html#173233086">(Aug 14 2019 at 19:15)</a>:</h4>
<p>It wouldnt help in the lexer</p>



<a name="173233187"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/What%27s%20the%20best%20way%20to%20report%20fatal%20errors%3F/near/173233187" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/What&#x27;s.20the.20best.20way.20to.20report.20fatal.20errors.3F.html#173233187">(Aug 14 2019 at 19:16)</a>:</h4>
<p>Or rather, you need the lexer to return an <code>Err</code> for cascading errors not to happen</p>



<a name="173233236"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/What%27s%20the%20best%20way%20to%20report%20fatal%20errors%3F/near/173233236" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/What&#x27;s.20the.20best.20way.20to.20report.20fatal.20errors.3F.html#173233236">(Aug 14 2019 at 19:17)</a>:</h4>
<p>What about <code>Level::PhaseFatal</code>? Semantically, it is exactly what I need here, but, although this variant exists, it isn't actually used anywhere =/ There's an irony in that <code>Level::PhaseFatal</code> is the only documented error variant</p>



<a name="173233352"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/What%27s%20the%20best%20way%20to%20report%20fatal%20errors%3F/near/173233352" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/What&#x27;s.20the.20best.20way.20to.20report.20fatal.20errors.3F.html#173233352">(Aug 14 2019 at 19:18)</a>:</h4>
<p><span class="user-mention" data-user-id="119031">@Esteban Küber</span> returning <code>Result</code> is no-go for IDE use-case. IDEs should basically <em>never</em> stop processing. Cascading errors is not a problem if you emit squiggly underlines, and it's important to make at least some sense of the code after the error.</p>



<a name="173233367"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/What%27s%20the%20best%20way%20to%20report%20fatal%20errors%3F/near/173233367" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/What&#x27;s.20the.20best.20way.20to.20report.20fatal.20errors.3F.html#173233367">(Aug 14 2019 at 19:18)</a>:</h4>
<p>For example, here's how Kotlin deals with unclosed strings:</p>
<p><a href="/user_uploads/4715/ryuyMG70WETrvs4s7juOfpqO/pasted_image.png" target="_blank" title="pasted_image.png">pasted image</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/ryuyMG70WETrvs4s7juOfpqO/pasted_image.png" target="_blank" title="pasted image"><img src="/user_uploads/4715/ryuyMG70WETrvs4s7juOfpqO/pasted_image.png"></a></div>



<a name="173233411"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/What%27s%20the%20best%20way%20to%20report%20fatal%20errors%3F/near/173233411" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/What&#x27;s.20the.20best.20way.20to.20report.20fatal.20errors.3F.html#173233411">(Aug 14 2019 at 19:19)</a>:</h4>
<p>there's a bunch of errors (8), but they are not that harmful, b/c they are not printed to the terminal, and IDE does useful stuff for the following declaration</p>



<a name="173234357"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/What%27s%20the%20best%20way%20to%20report%20fatal%20errors%3F/near/173234357" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/What&#x27;s.20the.20best.20way.20to.20report.20fatal.20errors.3F.html#173234357">(Aug 14 2019 at 19:31)</a>:</h4>
<p>I've found returning Results to be super annoying in practice</p>



<a name="173234366"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/What%27s%20the%20best%20way%20to%20report%20fatal%20errors%3F/near/173234366" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/What&#x27;s.20the.20best.20way.20to.20report.20fatal.20errors.3F.html#173234366">(Aug 14 2019 at 19:31)</a>:</h4>
<p>it seems like sentinel is better overall</p>



<a name="173234542"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/What%27s%20the%20best%20way%20to%20report%20fatal%20errors%3F/near/173234542" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/What&#x27;s.20the.20best.20way.20to.20report.20fatal.20errors.3F.html#173234542">(Aug 14 2019 at 19:33)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> the approaches seem isomorphic tho? -- at least with <code>Result</code> you get monad powers</p>



<a name="173234646"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/What%27s%20the%20best%20way%20to%20report%20fatal%20errors%3F/near/173234646" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/What&#x27;s.20the.20best.20way.20to.20report.20fatal.20errors.3F.html#173234646">(Aug 14 2019 at 19:34)</a>:</h4>
<p>In a compiler I wrote over the last weeks I experimented without sentinels and marked the spans as "already errored" and silenced further warnings on spans with such markings</p>



<a name="173235231"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/What%27s%20the%20best%20way%20to%20report%20fatal%20errors%3F/near/173235231" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/What&#x27;s.20the.20best.20way.20to.20report.20fatal.20errors.3F.html#173235231">(Aug 14 2019 at 19:42)</a>:</h4>
<p>Result doesn't work well for "log and continue" I think, since you end up writing equivalent of unwrap_or(sentinel) anyway essentially</p>



<a name="173235391"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/What%27s%20the%20best%20way%20to%20report%20fatal%20errors%3F/near/173235391" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/What&#x27;s.20the.20best.20way.20to.20report.20fatal.20errors.3F.html#173235391">(Aug 14 2019 at 19:44)</a>:</h4>
<p>The approaches may <em>seem</em> isomorphic but, in general, I found it much smoother to have (e.g.) an <code>Err</code> variant inside of <code>Ty</code> than to make <code>Ty</code> always be <code>Result&lt;Ty, Error&gt;</code> (and so forth for other types). Maybe, if you were thorough, they would both work out roughly the same.</p>



<a name="173235484"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/What%27s%20the%20best%20way%20to%20report%20fatal%20errors%3F/near/173235484" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/What&#x27;s.20the.20best.20way.20to.20report.20fatal.20errors.3F.html#173235484">(Aug 14 2019 at 19:45)</a>:</h4>
<p>Maybe <code>Result</code> is the wrong monad; <a href="http://hackage.haskell.org/package/monad-validate-1.2.0.0/docs/Control-Monad-Validate.html" target="_blank" title="http://hackage.haskell.org/package/monad-validate-1.2.0.0/docs/Control-Monad-Validate.html">http://hackage.haskell.org/package/monad-validate-1.2.0.0/docs/Control-Monad-Validate.html</a> seems interesting; Something more <code>Writer</code>-monad like might be better</p>



<a name="173235751"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/What%27s%20the%20best%20way%20to%20report%20fatal%20errors%3F/near/173235751" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/What&#x27;s.20the.20best.20way.20to.20report.20fatal.20errors.3F.html#173235751">(Aug 14 2019 at 19:48)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> Yeah I suppose it's a question of biasing towards handling or not handling the error case. Having <code>::Err</code> inside might also be better for introducing (possibly named) typed holes and whatnot later</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>